import 'package:basic_library/basic_library.dart';
import 'package:flutter/material.dart';

///
/// 上图片，下文字，右边有角标数的 button
///
class QTopIconBottomTextNumButton extends StatelessWidget {
  final String icon;
  final String title;
  final double height;
  final double width;
  final int count;
  final GestureTapCallback? tapCallback;

  const QTopIconBottomTextNumButton({
    Key? key,
    required this.icon,
    required this.title,
    required this.height,
    required this.width,
    this.count = 0,
    this.tapCallback,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (tapCallback != null) {
          tapCallback!();
        }
      },
      child: Stack(
        children: [
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 3, vertical: 3),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Image.asset(icon,
                    fit: BoxFit.cover, height: height, width: width),
                const SizedBox(height: 2),
                Text(
                  title,
                  style: const TextStyle(fontSize: 14, color: Colors.black),
                ),
              ],
            ),
          ),

          /// 未读数
          Positioned(
            top: 5,
            right: 3,
            child: unreadCountWidget(
              count,
            ),
          ),
        ],
      ),
    );
  }
}
